home *** CD-ROM | disk | FTP | other *** search
Wrap
/*###########################################################*/ /*# #*/ /*# File: CDevTester.c #*/ /*# Version: 1.0 #*/ /*# Author: #*/ /*# Copyright: (c) 1991 by Apple Computer, Inc. #*/ /*# #*/ /*# Description: This file contains the cdev C #*/ /*# routine used by the CDevTester CDEV. #*/ /*# #*/ /*#---------------------------------------------------------#*/ /*# #*/ /*# Development History: #*/ /*# #*/ /*# Who Date The Modification #*/ /*# --- -------- ---------------- #*/ /*# RAH 03/27/91 Initial release #*/ /*# #*/ /*###########################################################*/ #include <Types.h> #include <GSOS.h> #include <Quickdraw.h> #include <Font.h> #include <Memory.h> #include <IntMath.h> #include <Event.h> #include <ProDOS.h> #include <Locator.h> #include <Control.h> #include <Window.h> #include <List.h> #include <Scrap.h> #include <Dialog.h> #include <Menu.h> #include <Desk.h> #include <StdFile.h> #include <QDAUX.h> #include <Print.h> #include <MiscTool.h> #include <LineEdit.h> #include <Resources.h> #include <malloc.h> #include "CDevTester.h" #include "rDefs.h" extern unsigned SaveDB (); extern void RestoreDB (); /* Some globals */ int OriginalKeyRepeatRate; int UpdateFlag = 0; CtlRecHndl CDevCtlHandle; CtlRecHndl TimeCtlHandle; CtlRecHndl AboutBoxCtlHandle; WindowPtr MyCDevWindowPtr; WmTaskRec myTaskRec; /* Declare a text buffer to hold the ASCIITimeCtl, a static text control which points to the text */ /* buffer, and a handle to create the control. These are used to display the time that show that */ /* the RunCDev message is being passed. */ static char ASCIITimeText[30]; StaticTextTemplate ASCIITimeCtl = { 8, /* p count */ 100L, /* control ID */ {130,25,145,185}, /* ctl rect */ (long) statTextControl, /* procRef */ 0x0001, /* flag */ 0x1000, /* moreFlags */ 0L, /* refCon */ (Ref) ASCIITimeText, /* textref */ 20 /* textSize*/ }; /*###########################################################*/ /*# Actual CDEV, this is called by the control panel #*/ /*###########################################################*/ /* This routine is eventually linked and then placed into a cdev code resource. The only requirements are that this routine is at the beginning of the resource so if the CDEV has any other routines they must follow this one. The cdev's resource fork is always opened when a call to the cdev is made. The cdev can also assume that the current port is set to the ctl panel window except in the boot message, where quickdraw isn't even started, and in the about message, where it is the port of the help window. All normal managers will be stared up for all calls except the boot call, which will only have miscTools & Resource Manager started. */ pascal long CDEV(message,data1, data2) int message; long data1; long data2; { unsigned oldDBR; int retCode; static char AlertString[175]; oldDBR = SaveDB(); /* set up DBR correctly */ retCode = 0; /* initialize the function result to zero, so that we will work in future versions of the Control Panel! */ switch(message) { case MachineCDEV: /* Message 1 */ /* This is called if the wantMachine bit is set in the CDEV flags. It enables the CDEV to do further checking to see if it makes sense for the CDEV to be visible to the user or not. For instance, if the CDEV controls a setting for some hardware, we could check to see if the hardware is really connected. The parameters are undefined for this call and the result is passed back as the function result. 0 = don't show this CDEV, <>0 = show this CDEV. The control panel will do some machine checking even before calling this routine by checking the ROM version number against the machine field of the cdev flags resource */ retCode = MachineCDEVProc(); break; case BootCDEV: /* Message 2 */ /* if the wantBoot flag is set, this routine will be called during the startup sequence. The control panel takes care of drawing the "boot" icon. When this call is made, the machine state is bad at best. QuickDraw is not even started up. The parameters to this call are undefined. */ break; case ShutDownCDEV: /* Message 3 */ /* if the wantShutDown bit is set in the CDEV flags resource then this routine is called when the user either disables the CDEV or *someday* when the machine is being turned off. It gives the CDEV a chance to turn itself off (or any hardware or software it controls). The parameters are undefined in this call. */ break; case InitCDEV: /* Message 4 */ /* if the wantInit flag is set, then this message is passed with data1 = the control panel's Window ptr. By this time the CreateCDEV call will have been made and thus the controls used by the CDEV created. This call enables the CDEV to initialize the controls before they are displayed. */ InitCDEVProc (data1); break; case CloseCDEV: /* Message 5 */ /* The CloseCDEV message is passed if the wantClose bit is set in the CDEV flags and the control panel is closing or when the user selects another CDEV. During this call data1 = WindowPtr. In general, CDEVs can do any memory disposal and saving of settings during this call. The disposal of the CDEV's controls is handled automatically by the Control Panel. */ CloseCDEVProc(); break; case EventsCDEV: /* Message 6 */ /* if the wantEvents bit is set, the control panel will call this routine with data1 = ptr to the event record. This allows the cdev to intercept and even *gasp* change the event record before it is handled by the control panel. */ EventsCDEVProc(data1); break; case CreateCDEV: /* Message 7 */ /* if the wantCreate bit is set, this message is called with the control panel's Window ptr passed in data1. The cdev must create any controls it has during this call. The CDEV's resource fork is open during this call so resource manager calls can be made. All controls rectangles MUST be relative to 0,0. The control panel handles offsetting controls to the proper place in the Window. Initialization of the controls needs to be done in the InitCDEV call. Just create the controls in this call. */ CreateCDEVProc(data1); break; case AboutCDEV: /* Message 8 */ /* if the wantAbout bit is set in the CDEV flags, this call is made when the user selects help. Data1 = Window ptr to the help Window. The control panel automatically handles the icon, author, and version # display.*/ AboutCDEVProc(data1); break; case RectCDEV: /* Message 9 */ /* if a CDEV has a different size data rectangle depending on some state, like the printer & modem port cdev's, then you can get a chance to tell the control panel this by setting the wantRect bit in the CDEV flags. In this call, data1 is a ptr to the rect and can be directly modified by the CDEV. */ RectCDEVProc(data1); break; case HitCDEV: /* Message 10 */ /* if the CDEV wants to know when a control has been "hit", it can set the wantHit bit in the CDEV flags. When called, data1 = Hdl to Ctl Hit & data2 = Ctl ID of hit control. This message allows the CDEV to perform actions based on the control that was selected by the user.*/ HitCDEVProc (data2); break; case RunCDEV: /* Message 11 */ /* This message is called if the "wantRun" bit is set in the CDEV flags. It enables CDEVs like time to update the display. It is called every second - every time the DARun call is issued to the control panel. -no parameters are passed to this routine. */ RunCDEVProc(); break; case EditCDEV: /* Message 12 */ EditCDEVProc(data1,data2); break; } /* end of switch */ RestoreDB(oldDBR); return(retCode); } /* end of CDEV function */ /* MachineCDEV routine Message 1 */ int MachineCDEVProc() { int retCode; InitCursor(); AlertWindow (0x0000,NULL,"30/Message = MachineCDEV/^OK"); retCode = 1; /* Set the retCode to non-zero value so CDEV is opened. */ return retCode; } /* BootCDEV routine Message 2 */ /* Look for the CDEV Icon at boot time */ /* Reserved Message 3 */ /* InitCDEV routine Message 4 */ InitCDEVProc(MyCDEVWindowPtr) WindowPtr MyCDEVWindowPtr; { HiliteControl (0x00FF,GetCtlHandleFromID(MyCDevWindowPtr,(long)NullEventCheckBox)); HiliteControl (0x00FF,GetCtlHandleFromID(MyCDevWindowPtr,(long)SwitchEventCheckBox)); HiliteControl (0x00FF,GetCtlHandleFromID(MyCDevWindowPtr,(long)DeskAccEventCheckBox)); HiliteControl (0x00FF,GetCtlHandleFromID(MyCDevWindowPtr,(long)DriverEventCheckBox)); InitCursor(); AlertWindow (0x0000,NULL,"30/Message = InitCDEV\rSome controls have been deactivated./^OK"); } /* CloseCDEV routine Message 5 */ CloseCDEVProc() { if (OriginalKeyRepeatRate == 4) /* Was the No Repeat set before we opened */ { WriteBParam (0x0004,0x002D); /* Restore any changes to the BatteryRam */ UpdateSysBRam (); /* Match the system to BatteryRam */ } AlertWindow (0x0000,NULL,"30/Message = CloseCDEV/^OK"); } /* EventsCDEVProc Message 6 */ EventsCDEVProc(CDEVEventRecPtr) EventRecordPtr CDEVEventRecPtr; { myTaskRec = *(CDEVEventRecPtr); /* Put the Event Record into a buffer */ switch (myTaskRec.what) /* Switch on the what field of that record */ { case nullEvt: NullEvtProc(); break; case mouseDownEvt: MouseDownEvtProc(); break; case mouseUpEvt: MouseUpEvtProc(); break; case keyDownEvt: KeyDownEvtProc(); break; case autoKeyEvt: AutoKeyEvtProc(); break; case updateEvt: UpdateEvtProc(); break; case activateEvt: ActivateEvtProc(myTaskRec); break; case switchEvt: break; case deskAccEvt: break; case driverEvt: break; } } /* CreateCDEV routine Message 7 */ CreateCDEVProc(ThisCDEVWindowPtr) WindowPtr ThisCDEVWindowPtr; { MyCDevWindowPtr = ThisCDEVWindowPtr; /* Initialize global WindowPtr to returned Ptr from create */ SetBRAMProc(); /* Set AutoKey in BRAM if not already set and save old setting */ CDevCtlHandle = NewControl2(MyCDevWindowPtr,9,(long)myCtrlList); /* Create all the resource controls */ TimeCtlHandle = NewControl2(MyCDevWindowPtr,0,&ASCIITimeCtl); /* Create the time control only (defined on the stack) */ } /* AboutCDEV routine Message 8 */ AboutCDEVProc(AboutWIndowPtr) WindowPtr AboutWIndowPtr; { AboutBoxCtlHandle = NewControl2(AboutWIndowPtr,2,(long)AboutID); } /* RectCDEV routine Message 9 */ RectCDEVProc(RectPtr) pointer RectPtr; { InitCursor(); AlertWindow (0x0000,NULL,"40/Message = RectCDEV\rThe CDEV window Rect is being resized to:\r{0,0,200,165}.\rThe Rect in the CDEV resource is:\r{0,0,200,175}/^OK"); SetRect (RectPtr,0,0,200,150); } /* HitCDEV routine Message 10 */ HitCDEVProc(MyControlID) long MyControlID; { if (MyControlID == CheckABoxText) { AlertWindow (0x0000,NULL,"30/Message = HitCDEV\rControl Hit = CheckABoxText/^OK"); } else if (MyControlID == ASCIITimeStaticText) { AlertWindow (0x0000,NULL,"30/Message = HitCDEV\rControl Hit = ASCIITimeStaticText/^OK"); } } /* RunCDEV routine Message 11 */ RunCDEVProc() { int i; if (FrontWindow() == MyCDevWindowPtr) { ReadAsciiTime (ASCIITimeText); for (i = 0; i < 20; i++) { ASCIITimeText[i] = ASCIITimeText[i]&0x7F; } DrawOneCtl(TimeCtlHandle); }; } /* EditCDEVProc Message 12 */ EditCDEVProc(EditCode,EditCDEVWindowPtr) long EditCode; WindowPtr EditCDEVWindowPtr; { static char AlertString[175]; if(EditCode == 0x0005) { sprintf(AlertString,"30/Message = EditCDEV\rEditCode = $%lxL (Undo)\rWindow Pointer = $%lxL/^#OK", EditCode, EditCDEVWindowPtr); AlertWindow (0x0000,NULL,AlertString); } if(EditCode == 0x0006) { sprintf(AlertString,"30/Message = EditCDEV\rEditCode = $%lxL (Cut)\rWindow Pointer = $%lxL/^#OK", EditCode, EditCDEVWindowPtr); AlertWindow (0x0000,NULL,AlertString); } if(EditCode == 0x0007) { sprintf(AlertString,"30/Message = EditCDEV\rEditCode = $%lxL (Copy)\rWindow Pointer = $%lxL/^#OK", EditCode, EditCDEVWindowPtr); AlertWindow (0x0000,NULL,AlertString); } if(EditCode == 0x0008) { sprintf(AlertString,"30/Message = EditCDEV\rEditCode = $%lxL (Paste)\rWindow Pointer = $%lxL/^#OK", EditCode, EditCDEVWindowPtr); AlertWindow (0x0000,NULL,AlertString); } if(EditCode == 0x0009) { sprintf(AlertString,"30/Message = EditCDEV\rEditCode = $%lxL (Clear)\rWindow Pointer = $%lxL/^#OK", EditCode, EditCDEVWindowPtr); AlertWindow (0x0000,NULL,AlertString); } } /* Here's all the Event Handling Procs */ NullEvtProc() { if (GetCtlValue(GetCtlHandleFromID(MyCDevWindowPtr,(long)NullEventCheckBox)) != 0) { AlertWindow (0x0000,NULL,"30/Message = EventsCDEV\rEvent Code = nullEvt/^OK"); ResetControls(); } } MouseDownEvtProc() { if (GetCtlValue(GetCtlHandleFromID(MyCDevWindowPtr,(long)MouseDownEventCheckBox)) != 0) { AlertWindow (0x0000,NULL,"30/Message = EventsCDEV\rEvent Code = mouseDownEvt/^OK"); ResetControls(); } } MouseUpEvtProc() { if (GetCtlValue(GetCtlHandleFromID(MyCDevWindowPtr,(long)MouseUpEventCheckBox)) != 0) { AlertWindow (0x0000,NULL,"30/Message = EventsCDEV\rEvent Code = mouseUpEvt/^OK"); ResetControls(); } } KeyDownEvtProc() { if (GetCtlValue(GetCtlHandleFromID(MyCDevWindowPtr,(long)KeyDownEventCheckBox)) != 0) { AlertWindow (0x0000,NULL,"30/Message = EventsCDEV\rEvent Code = keyDownEvt/^OK"); ResetControls(); } } AutoKeyEvtProc() { if (GetCtlValue(GetCtlHandleFromID(MyCDevWindowPtr,(long)AutoKeyEventCheckBox)) != 0) { AlertWindow (0x0000,NULL,"30/Message = EventsCDEV\rEvent Code = autoKeyEvt/^OK"); ResetControls(); } } UpdateEvtProc() { if (GetCtlValue(GetCtlHandleFromID(MyCDevWindowPtr,(long)UpdateEventCheckBox)) != 0 && UpdateFlag == 0) { ++UpdateFlag; AlertWindow (0x0000,NULL,"30/Message = EventsCDEV\rEvent Code = updateEvt/^OK"); UpdateFlag = 0; ResetControls(); } } ActivateEvtProc(myTaskRec) WmTaskRec myTaskRec; { if (GetCtlValue(GetCtlHandleFromID(MyCDevWindowPtr,(long)ActivateEventCheckBox)) != 0) { if ((myTaskRec.modifiers&0x0001) != 0) { AlertWindow (0x0000,NULL,"30/Message = EventsCDEV\rEvent Code = activateEvt/^OK"); ResetControls(); } else if ((myTaskRec.modifiers&0x0001) == 0) { AlertWindow (0x0000,NULL,"30/Message = EventsCDEV\rEvent Code = deactivateEvt/^OK"); } } } /* A routine to reset controls state so that some events don't pile up */ ResetControls () { SetCtlValue (0,GetCtlHandleFromID(MyCDevWindowPtr,(long)NullEventCheckBox)); SetCtlValue (0,GetCtlHandleFromID(MyCDevWindowPtr,(long)MouseDownEventCheckBox)); SetCtlValue (0,GetCtlHandleFromID(MyCDevWindowPtr,(long)MouseUpEventCheckBox)); SetCtlValue (0,GetCtlHandleFromID(MyCDevWindowPtr,(long)KeyDownEventCheckBox)); SetCtlValue (0,GetCtlHandleFromID(MyCDevWindowPtr,(long)AutoKeyEventCheckBox)); SetCtlValue (0,GetCtlHandleFromID(MyCDevWindowPtr,(long)UpdateEventCheckBox)); SetCtlValue (0,GetCtlHandleFromID(MyCDevWindowPtr,(long)ActivateEventCheckBox)); /* SetCtlValue (0,GetCtlHandleFromID(MyCDevWindowPtr,(long)SwitchEventCheckBox)); SetCtlValue (0,GetCtlHandleFromID(MyCDevWindowPtr,(long)DeskAccEventCheckBox)); SetCtlValue (0,GetCtlHandleFromID(MyCDevWindowPtr,(long)DriverEventCheckBox)); */ } /* Routine to set BRAM to allow autokey and save old BRAM setting */ SetBRAMProc() { if (ReadBParam (0x002D) == 0x0004) /* Is the No-Repeat set? */ { OriginalKeyRepeatRate = 4; /* Initialize storage variable */ WriteBParam (0x0002,0x002D); /* If so, change it to 0.75 sec delay. */ UpdateSysBRam (); } } /* This routine updates the RAM coppy of the BRAM parameters to match the BRAM. */ UpdateSysBRam () { asm /* Update RAM copy of parameter-RAM */ { phd /* save direct page register word on stack */ phb /* save data bank register byte on stack */ pea #0x0 /* push two bytes of 0 on the stack */ plb /* set data bank register byte to 0 */ plb /* clean up extraneous byte from stack */ php /* save processor status register byte on stack */ sep #0x30 /* set processor status to shortm+shortx */ sec /* set carry so ToBRAMSetup won't alter slot setup */ jsl 0xE10094 /* call ToBRAMSetup */ plp /* restore processor status mode byte from stack */ plb /* restore data bank register byte from stack */ pld /* restore direct page register word from stack */ } }